package cn.hdu.liang.ch4;


public class ThreadLocalDemo {
    private static volatile ThreadLocal<String> userId = new ThreadLocal<>();

    public static void main(String[] args) {
        Runnable r = () -> {
            String name = Thread.currentThread().getName();
            if(name.equals("A")) {
                userId.set("AAAA");
            } else {
                userId.set("BBBB");
            }
            System.out.println(name + " " + userId.get());
        };
        Thread thdA = new Thread(r, "A");
        Thread thdB = new Thread(r, "B");
        thdA.start();
        thdB.start();
    }
}
